$(function () {
  GoodCog();
  GoodMaxRanking();
  goodMinRanking();
});

function GoodCog() {
  let data = [
    {name: "获奖（表彰）信息", value: 112, score: 4},
    {name: "科技创新", value: 112, score: 4},
    {name: "科技创新（定额）", value: 88, score: 4},
    {name: "社会公益信息", value: 65, score: 3},
  ];
  let total = 0, legendData = [];
  data.forEach(function (item) {
    legendData.push(item.name);
    total += parseInt(item.score);
  });
  let myChart = echarts.init(document.getElementById("goodCog"));
  myChart.setOption({
    title: {
      text: "{a|" + total + "}\n总得分",
      top: "110",
      left: "center",
      textStyle: {
        fontWeight: 500,
        fontSize: 16,
        rich: {
          a: {
            fontSize: 30,
            fontWeight: 600,
            lineHeight: 36
          }
        }
      }
    },
    tooltip:{
      trigger:"item",
      formatter:"{b}：{c}次"
    },
    legend: {
      data: legendData,
      bottom: 22,
      left: "center",
      icon: "circle",
      orient: 'vertical',
      itemWidth: 10,
      itemHeight: 10,
      itemGap: 15,
      formatter: function (name) {
        let index = 0, total = 0;
        data.forEach(function (item, i) {
          if (item.name === name) {
            index = i;
          }
          total += parseInt(item.value)
        });
        const percentage = (parseInt(data[index].value) / total * 100).toFixed(0) + "%";
        return name + "   " + data[index].value + "次   " + percentage
      }
    },
    color: ["#1665D8", "#18CBAF", "#F6AB2E", "#E0414A"],
    series: [{
      type: "pie",
      clockwise: false,
      center: ["50%", "35%"],
      radius: [60, 100],
      label: {
        show: false
      },
      data: data
    }]
  });
  $(window).resize(myChart.resize);
}

function GoodMaxRanking(){
  let myChart = echarts.init(document.getElementById("goodMaxRanking"));
  myChart.setOption({
    title:{
      text:"认定次数最少top5指标",
      left:25,
      top:20,
      textStyle:{
        fontSize:15
      }
    },
    tooltip: {
      trigger: "item",
      formatter:"良好信用认定次数：{c}次"
    },
    grid: {
      left: 30,
      top: 65,
      right: 30,
      bottom: 40,
      // containLabel: true
    },
    xAxis: {
      show: true,
      axisTick: 'none',
      axisLine: 'none',
      axisLabel:{
        color:"#999",
        formatter:"{value}次"
      },
      splitLine: {
        lineStyle: {
          type: "dashed",
          color: "#eeeeee"
        }
      }
    },
    yAxis: {
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: "none",
      data: ["这里是良好行为名称这里是良好行为名称","这里是良好行为名称","这里是良好行为名称良好行为名称","这里是良好行为名称这里是良好行为名称","这里是良好行为名称"]
    },
    series: [
      {
        type: 'bar',
        barWidth: 12,
        itemStyle: {
          color: '#3BAD4B',
          barBorderRadius: 2,
          emphasis:{
            color: '#3BAD4B',
          }
        },
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: [0, -20],
            textStyle: {
              fontSize: 14
            },
            formatter: function (data) {
              return data.name;
            },
          }
        },
        data: [11,23,36,46,53],
        z: 2
      },
      {
        type: 'scatter',
        hoverAnimation: false,
        label: {
          color: "#3BAD4B",
          show: true,
          position: "right",
          padding:[0,0,-2,-7],
          textStyle: {
            fontSize: 14,
          },
          formatter: function (param) {
            return param.value;
          },
        },
        itemStyle:{
          color:"transparent"
        },
        data: [11,23,36,46,53],
        z: 2,
      }
    ]
  });
  $(window).resize(myChart.resize);
}

function goodMinRanking(){
  let myChart = echarts.init(document.getElementById("goodMinRanking"));
  myChart.setOption({
    title:{
      text:"认定次数最多top5指标",
      left:25,
      top:20,
      textStyle:{
        fontSize:15
      }
    },
    tooltip: {
      trigger: "item",
      formatter:"良好信用认定次数：{c}次"
    },
    grid: {
      left: 30,
      top: 65,
      right: 30,
      bottom: 40,
      // containLabel: true
    },
    xAxis: {
      show: true,
      axisTick: 'none',
      axisLine: 'none',
      axisLabel:{
        color:"#999",
        formatter:"{value}次"
      },
      splitLine: {
        lineStyle: {
          type: "dashed",
          color: "#eeeeee"
        }
      }
    },
    yAxis: {
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: "none",
      data: ["这里是良好行为名称这里是良好行为名称","这里是良好行为名称","这里是良好行为名称良好行为名称","这里是良好行为名称这里是良好行为名称","这里是良好行为名称"]
    },
    series: [
      {
        type: 'bar',
        barWidth: 12,
        itemStyle: {
          color: '#1665D8',
          barBorderRadius: 2,
          emphasis:{
            color: '#1665D8',
          }
        },
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: [0, -20],
            formatter: function (data) {
              console.log(data)
              return "{a|"+(data.dataIndex+1)+"}"+ data.name;
            },
            textStyle: {
              fontSize: 14,
              rich:{
                a: {
                  color:"red",
                  fontSize:24,
                  padding: [-20,10,0,-20]
                }
              }
            }
          }
        },
        data: [53,46,36,23,11],
        z: 2
      },
      {
        type: 'scatter',
        hoverAnimation: false,
        label: {
          color: "#1665D8",
          show: true,
          position: "right",
          padding:[0,0,-2,-7],
          textStyle: {
            fontSize: 14,
          },
          formatter: function (param) {
            return param.value;
          },
        },
        itemStyle:{
          color:"transparent"
        },
        data: [53,46,36,23,11],
        z: 2,
      }
    ]
  });
  $(window).resize(myChart.resize);
}
